<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-08-14 16:53:46
 * @LastEditTime: 2020-07-17 14:01:29
 * @LastEditors: Please set LastEditors
 -->
<template>
    <search-table
      :columns="taskCol" 
      :data="taskData"
      :total="taskTotal"
      :page.sync="taskCurrentPage"
      :size.sync="taskItemPage"
      @change-size="switchTaskItemPage"
      @change-page="switchineTaskCurrentPage"
    >
      <template slot="button-group">
        <Button
          type="primary"
          ghost
          @click="createFlagTask"
          :disabled="disabledAllBtn"
          class="zIndexStyleBtn"
          ><Icon type="ios-add" :size="16" class="position_i" />创建任务</Button
        >
        <!-- <BatchRemove
                        class="zIndexStyleBtn"
                        :dataNum="selectedData.length"
                        @on-ok="deleteManyTask"
                        @on-cancel="cancel"></BatchRemove> -->
        <!-- <Button type="primary" ghost @click="taskConfigerMess = true" :disabled="disabledAllBtn" class="zIndexStyleBtn"><Icon type="md-settings" :size="16" class="position_i"/>配置管理</Button> -->
      </template>
      <!-- <template slot="select-group">
                <Select filterable v-model="queryInfo.status" clearable @on-change="debounceSearch" placeholder="任务状态">
                    <Option value="completed" key="completed">已完成</Option>
                    <Option value="running" key="running">运行中</Option>
                    <Option value="initialized" key="initialized">初始化</Option>
                    <Option value="failed" key="error">已失败</Option>
                </Select>
            </template>
            <template slot="input-group">
                <Input v-model="queryInfo.name" placeholder="名称" @on-change="debounceSearch" clearable/>
            </template> -->
      <!-- <card-list :columns="columnsData" :data="taskData"></card-list> -->
    <Modal
      v-model="createFlagTaskModal"
      :title="judgePanelType ? '创建任务' : '修改任务'"
      width="600"
      ok-text="确定"
      :mask-closable="false"
      :loading="createFlagTaskModalLoading"
      @on-ok="ok"
      @on-cancel="cancel"
    >
      <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
        <FormItem label="名称" prop="name">
          <Input
            v-model="formValidate.name"
            placeholder="请输入任务名称"
            clearable
            :maxlength="64"
          ></Input>
        </FormItem>
        <!-- <FormItem label="类型" prop="taskMode">
                    <RadioGroup v-model="formValidate.taskMode">
                        <Radio label="normal" :disabled="disabledTepBol">流程任务</Radio>
                        <Radio label="preset" :disabled="disabledTepBol">预设临机任务</Radio>
                    </RadioGroup>
                </FormItem> -->
        <FormItem v-model="formValidate.selectedVmData" label="虚拟机">
          <span class="starlet">*</span>
          <input type="hidden" />
          <div class="flex-wrap">
            <Tag
              v-for="item in formValidate.selectedVmData"
              :key="item.name"
              :name="item.id"
              closable
              @on-close="handleClose2"
              color="primary"
              type="dot"
              >{{ item.name }}</Tag
            >
          </div>
        </FormItem>
        <div style="text-align:right">
          <Button type="primary" @click="addSelectedData" style="margin-right:17px">添加</Button>
          <Input
            placeholder="请输入名称"
            style="width: 210px"
            v-model="formValidate.vmName"
            clearable
          ></Input>
          <Input
            placeholder="请输入IP"
            style="width: 210px"
            v-model="formValidate.vmIP"
            clearable
          ></Input>
          <Button type="primary" @click="refreshVmList" style="margin-left:5px">搜索</Button>
        </div>
        <Table
          border
          ref=""
          :columns="columnsVmList"
          :data="dataVmList"
          :stripe="showStripe"
          :show-header="showHeader"
          :size="tableSize"
          style="margin-top:10px"
          @on-selection-change="getSelectedData"
        ></Table>
        <Page
          :total="vmTotal"
          :current="vmCurrentPage"
          :page-size="vmItemPage"
          :show-total="true"
          @on-change="switchineVmCurrentPage"
          @on-page-size-change="switchVmItemPage"
          class-name="pageStyleVm"
          show-elevator
        />

        <FormItem label="指令" prop="instruct" style="margin-top:10px">
          <!-- <Icon type="md-add-circle" :size="20" style="cursor:pointer" @click="taskConfigerMess = true"/> -->
          <Select filterable
            v-model="formValidate.instruct"
            placeholder="请选择指令"
            filterable
            clearable
            @on-change="getInstructDeail"
          >
            <Option v-for="item in configurationData" :key="item.id" :value="item.id"
              >{{ item.name }}({{ item.note }})</Option
            >
          </Select>
        </FormItem>
        <FormItem label="参数" prop="" v-model="instructData[0].args">
          <div v-for="item in instructData[0].args" :key="item.id">
            <span style="color:red;font-size:18px;font-weight:800" v-show="item.mandatory">*</span>
            <span>{{ item.key + '(' + item.desc + ')' }}</span>
            <Input placeholder="请输入指令参数" clearable v-model="item.value"></Input>
          </div>
        </FormItem>
        <FormItem label="属性">
          <cusAttribute
            ref="cusAttribute"
            @func="getMsgFormSon"
            v-bind:msgVal="propertiesData"
          ></cusAttribute>
        </FormItem>
        <FormItem label="描述" prop="desc">
          <Input
            v-model="formValidate.desc"
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 5 }"
            placeholder="请输入内容"
            clearable
            :maxlength="200"
          ></Input>
        </FormItem>
      </Form>
    </Modal>
    <Modal v-model="taskDeailModal" title="任务启动详情" width="80%" :mask-closable="false">
      <Table
        border
        ref=""
        :columns="taskDeailColumns"
        :data="taskDeailData"
        :stripe="showStripe"
        :show-header="showHeader"
        :size="tableSize"
        @on-expand="hostDeail"
      ></Table>
    </Modal>
    <!-- <Modal 
            v-model="taskConfigerMess" 
            fullscreen 
            title="带外采集配置"
            okText = "关闭"
            cancelText=""
            @on-cancel = "clickEvent"
            @on-ok = "clickEvent"
        >
            <outbandCaptureCollect></outbandCaptureCollect>
        </Modal> -->
    <Modal
      v-model="taskCollectDeailPanel"
      width="80%"
      title="采集结果"
      okText="关闭"
      cancelText=""
      :mask-closable="false"
    >
      <div style="min-height: 150px;max-height: 800px;overflow: auto;" id="dataPanel">
        <h2 class="title" style="width:100%;text-align:center">未查询到采集结果</h2>
        <div id="reportTableDiv" class="tableData">
          <table id="reportTable"></table>
        </div>
      </div>
    </Modal>
  </search-table>
</template>

<!-- <script src="../../../static/const.js"></script> -->
<!-- <script src="../../../static/bootstrap/js/bootstrap.min.js"></script>
<script src="../../../static/bootstrap/js/bootstrapTable.js"></script> -->
<script>
import { validateName, taskMixin } from './taskMixin';
import axios from '@/libs/axios1';
import TableTooltip from '@/view/drill_compete/page/tableTooltip.vue';
import {
  showConfiguration,
  getAllVm,
  saveoutbandTask,
  getTaskListDetailData,
  getTaskList,
  deleteTask,
  taskDetail,
  amendTask,
  activeTask,
  taskDetailHis,
  hostDetail
} from '@/api/drill.js';
// import outbandCaptureCollect from '../configer/onceReadFileCollect'
export default {
  name: 'oncecapture',
  components: {
    TableTooltip
    // outbandCaptureCollect
  },
  props: ['disabledAllBtn'],
  mixins: [taskMixin],
  data() {
    return {
      taskCollectDeailPanel: false,
      taskConfigerMess: false,
      currentProjectId: '',
      taskTypeTable: 'once_capture',
      taskTypeTableTitle: '单次带外采集',
      selectedDataConfiger: [],
      selectedData: [],
      // amendTaskId:"",
      columnsData: [
        // {
        //     type: 'selection',
        //     width: 60,
        //     align: 'center'
        // },
        // {
        //     title:'任务ID',
        //     key:'id',
        //     align:'center'
        // },
        {
          title: '任务名称',
          key: 'name',
          align: 'center',
          placement: 'top-left'
        },
        {
          title: 'Profile',
          key: 'metadata.profile',
          align: 'center',
          render: (h, params) => {
            return params.row.metadata.profile
              ? h(TableTooltip, {
                  props: {
                    content: params.row.metadata.profile,
                    width: 100
                  }
                })
              : h('span', '无');
          }
        },
        {
          title: '信息',
          key: 'metadata.osInfo',
          align: 'center',
          render: (h, params) => {
            return params.row.metadata.osInfo
              ? h('TableTooltip', {
                  props: {
                    content: params.row.metadata.osInfo,
                    width: 150
                  }
                })
              : h('span', '无');
          }
        },
        {
          title: '指令',
          key: 'metadata.cmd',
          align: 'center',
          render: (h, params) => {
            let value = params.row.metadata.cmd;
            let oIP_ = [];
            value.forEach((item, i) => {
              oIP_.push(`<p>${item}</p>`);
            });
            return value.length > 0
              ? h('TableTooltip', {
                  props: {
                    width: 200,
                    showContent: value.join(' '),
                    content: oIP_.join('\n')
                  }
                })
              : h('span', '无');
          }
        },
        {
          title: '创建者',
          key: 'creatorName',
          align: 'center',
          tooltip: true,
          width: 100
        },
        {
          title: '创建时间',
          key: 'created',
          align: 'center',
          width: 140
        },
        {
          title: '状态',
          key: 'status',
          align: 'center',
          width: 60,
          placement: 'top-right',
          render: (h, params) => {
            return this.renderTaskStatus(h, params.row.status);
          }
        },
        {
          title: '详情',
          key: '-',
          align: 'center',
          // minWidth:140,
          render: (h, params) => {
            let statics = params.row.overview;
            let statusGroup = [];
            if (JSON.stringify(statics) != '{}') {
              for (let i in statics) {
                let text = '';
                switch (i) {
                  case 'running':
                    text = '运行中';
                    break;
                  case 'error':
                    text = '失败';
                    break;
                  case 'failed':
                    text = '失败';
                    break;
                  case 'completed':
                    text = '完成';
                    break;
                  case 'initialized':
                    text = '初始化';
                    break;
                  case 'starting':
                    text = '启动中';
                    break;
                  case 'closing':
                    text = '关闭中';
                    break;
                  default:
                    text = i;
                    break;
                }
                statusGroup.push(h('p', {}, text + ':' + statics[i]));
              }
            }
            // console.log(statusGroup)
            return h('div', {}, statusGroup);
          }
        },
        {
          title: '描述',
          key: 'description',
          align: 'center',
          tooltip: true,
          width: 150
        },
        // {
        //     title:'任务种类',
        //     key:'taskMode',
        //     align:'center',
        //     render:(h,params)=>{
        //         let _text = null;
        //         if(params.row.taskMode=="normal"){
        //             _text = "流程任务"
        //         }else if(params.row.taskMode=="temp"){
        //             _text = "实时任务"
        //         }else{
        //             _text = "预设临机任务"
        //         }
        //         return h('div',{},_text)
        //     }
        // },
        {
          title: '操作',
          key: '-',
          align: 'center',
          width: 350,
          placement: 'top-right',
          action: true,
          render: (h, params) => {
            let _this = this;
            let taskStatus = null;
            let taskBtnType = null;
            let btnStyle = null;
            if (params.row.taskMode == 'normal') {
              btnStyle = 'none';
            } else {
              btnStyle = 'inline-block';
            }
            switch (params.row.status) {
              case 'initialized':
                taskStatus = '开始';
                taskBtnType = 'success';
                break;
              case 'error':
              case 'failed':
                taskStatus = '开始';
                taskBtnType = 'success';
                break;
              case 'running':
                taskStatus = '停止';
                taskBtnType = 'error';
                break;
              case 'completed':
                taskStatus = '开始';
                taskBtnType = 'success';
                break;
              case 'starting':
                taskStatus = '停止';
                taskBtnType = 'error';
                break;
              case 'closing':
                taskStatus = '停止';
                taskBtnType = 'error';
                break;
              case 'stop_error':
                taskStatus = '停止';
                taskBtnType = 'error';
                break;
              default:
                break;
            }
            return h(
              'div',
              {
                attrs: {
                  class: 'btnCenter'
                }
              },
              [
                h(
                  'Poptip',
                  {
                    props: {
                      confirm: true,
                      title: '您确定要删除此任务吗？',
                      transfer: true
                    },
                    on: {
                      'on-ok': () => {
                        _this.deleteTask(params.row.id);
                      },
                      'on-cancel': () => {}
                    }
                  },
                  [
                    h(
                      'Button',
                      {
                        props: {
                          type: 'error',
                          size: 'small',
                          disabled: this.disabledAllBtn
                        },
                        attrs: {
                          title: '删除'
                        },
                        style: {
                          border: 'none',
                          background: 'none',
                          boxShadow: 'none'
                        }
                      },
                      [
                        h('img', {
                          attrs: {
                            //                          src: !this.setReBtnStatus(params.row) ?require('../../../assets/globalIcon/del.png'):require('../../../assets/globalIcon/dis-del.png'),
                            src: this.disabledAllBtn
                              ? require('../../../../../assets/project/delNote-d.png')
                              : require('../../../../../assets/project/delNote-h.png')
                          },
                          style: {
                            cursor: 'pointer',
                            //				                            'margin-right':'5px',
                            'vertical-align': 'middle',
                            //				                            width:'16px',
                            //				                            height:'auto',
                            display: 'inline-block',
                            marginBottom: '4px'
                          }
                        })
                        //				                    h('span',{
                        //				                        style: {
                        //				                            cursor: 'pointer',
                        //				//                          color:!this.setReBtnStatus(params.row) ? '#2d8cf0' : '#c5c8ce'
                        //											color:'#2d8cf0'
                        //				                        },
                        //				                    },'删除')
                      ]
                    )
                  ]
                ),
                h(
                  'Button',
                  {
                    props: {
                      type: 'text',
                      size: 'small',
                      disabled: this.disabledAllBtn
                    },
                    attrs: {
                      title: '修改'
                    },
                    style: {
                      border: 'none',
                      background: 'none',
                      boxShadow: 'none'
                    },
                    on: {
                      click: () => {
                        _this.updateTask(params.row.id);
                      }
                    }
                  },
                  [
                    h('img', {
                      attrs: {
                        //                          src: !this.setReBtnStatus(params.row) ? require('../../../assets/globalIcon/modify.png'):require('../../../assets/globalIcon/dis-modify2.png'),
                        src: this.disabledAllBtn
                          ? require('../../../../../assets/project/modifys.png')
                          : require('../../../../../assets/project/modifys-h.png')
                      },
                      style: {
                        cursor: 'pointer',
                        //			                            'margin-right':'5px',
                        'vertical-align': 'middle',
                        //			                            width:'16px',
                        //			                            height:'auto',
                        display: 'inline-block',
                        marginBottom: '4px'
                      }
                    })
                    //			                    h('span',{
                    //			                        style: {
                    //			                            cursor: 'pointer',
                    //			//                          color:!this.setReBtnStatus(params.row) ? '#2d8cf0' : '#c5c8ce'
                    //										color:'#2d8cf0'
                    //			                        },
                    //			                    },'修改')
                  ]
                ),
                h(
                  'Poptip',
                  {
                    props: {
                      confirm: true,
                      title: '您确定要' + taskStatus + '此任务吗？',
                      transfer: true
                    },
                    on: {
                      'on-ok': () => {
                        _this.activeTask(params.row.id, taskStatus);
                      },
                      'on-cancel': () => {}
                    }
                  },
                  [
                    h(
                      'Button',
                      {
                        props: {
                          //type:taskBtnType,
                          type: 'text',
                          size: 'small',
                          disabled: this.disabledAllBtn
                        },
                        title: {
                          title: taskStatus + '任务'
                        },
                        style: {
                          border: 'none',
                          background: 'none',
                          boxShadow: 'none',
                          display: btnStyle
                        }
                      },
                      [
                        h('img', {
                          attrs: {
                            //                          src: !this.setReBtnStatus(params.row) ? require('../../../assets/globalIcon/modify.png'):require('../../../assets/globalIcon/dis-modify2.png'),
                            src:
                              taskStatus == '停止'
                                ? this.disabledAllBtn
                                  ? require('../../../../../assets/scene/dis-stop-task.png')
                                  : require('../../../../../assets/scene/stop-task.png')
                                : this.disabledAllBtn
                                ? require('../../../../../assets/scene/dis-start-task.png')
                                : require('../../../../../assets/scene/start-task.png')
                          },
                          style: {
                            cursor: 'pointer',
                            //			                            'margin-right':'5px',
                            'vertical-align': 'middle',
                            //			                            width:'16px',
                            //			                            height:'auto',
                            display: 'inline-block',
                            marginBottom: '4px'
                          }
                        }),
                        h('span', {
                          style: {
                            cursor: 'pointer',
                            //                          color:!this.setReBtnStatus(params.row) ? '#2d8cf0' : '#c5c8ce'
                            color: '#2d8cf0'
                          }
                        }) //,taskStatus+'任务'
                      ]
                    )
                  ]
                ),
                h(
                  'Button',
                  {
                    props: {
                      type: 'primary',
                      size: 'small'
                      // style:{margin:'10px'}
                    },
                    style: {
                      border: 'none',
                      background: 'none',
                      boxShadow: 'none'
                    },
                    on: {
                      click: () => {
                        _this.taskDeail(params.row.id);
                      }
                    }
                  },
                  [
                    h('img', {
                      attrs: {
                        //                          src: !this.setReBtnStatus(params.row) ? require('../../../assets/globalIcon/modify.png'):require('../../../assets/globalIcon/dis-modify2.png'),
                        src: require('../../../../../assets/project/magnifier-h.png')
                      },
                      style: {
                        cursor: 'pointer',
                        //			                            'margin-right':'5px',
                        'vertical-align': 'middle',
                        //			                            width:'16px',
                        //			                            height:'auto',
                        display: 'inline-block',
                        marginBottom: '4px'
                      }
                    }),
                    h('span', {
                      style: {
                        cursor: 'pointer',
                        //                          color:!this.setReBtnStatus(params.row) ? '#2d8cf0' : '#c5c8ce'
                        color: '#2d8cf0'
                      }
                    }) //,'查看详情'
                  ]
                )
              ]
            );
          }
        }
      ],
      taskData: [],
      columnsVmList: [
        {
          type: 'selection',
          width: 60,
          align: 'center'
        },
        {
          title: this.$t('name'),
          key: 'name',
          align: 'center'
        },
        {
          title: 'IP',
          key: 'IP',
          align: 'center',
          render: (h, params) => {
            let value = params.row.IP;
            let oIP_ = [];
            value.forEach((item, i) => {
              oIP_.push(
                h(
                  'p',
                  {
                    color: '#000'
                  },
                  item
                )
              );
            });
            return h('div', oIP_);
          }
        },
        {
          title: 'Profile',
          key: 'profile',
          align: 'center'
        },
        {
          title: this.$t('Add'),
          key: 'add',
          align: 'center',
          width: 80,
          render: (h, params) => {
            let _this = params;
            // console.log(params.row)
            return h(
              'Button',
              {
                props: {
                  type: 'primary'
                },
                on: {
                  click: (e) => {
                    if (this.selectedVmDataTable.indexOf(_this.row.id) != -1) {
                      this.$Message.info('已添加');
                      return;
                    }
                    if (
                      this.selectedVmDataTable.length >= 1 &&
                      _this.row.profileId != this._profileId
                    ) {
                      this.$Message.info('只能选择profile相同的虚拟机');
                      return;
                    }
                    // alert('-')
                    this.addVmAfterTable(_this.row);
                    this.selectedVmDataTable.push(_this.row.id);
                    this.formValidate.selectedVmData.push({
                      name: _this.row.name,
                      id: _this.row.id
                    });
                    this._profileId = _this.row.profileId;
                    if (this._profileId) {
                      this.getInstructByVm();
                    } else {
                      this.selectedVmDataTable = [];
                      this.formValidate.selectedVmData = [];
                      this.judgeVmStatus();
                      this.$Message.error('查不到profileId');
                    }
                  }
                }
              },
              '+'
            );
          }
        }
      ],
      dataVmList: [],
      selectedVmDataTable: [],
      configurationData: [],
      createFlagTaskModalLoading: true,
      showBorder: false,
      showStripe: true,
      showHeader: true,
      showIndex: true,
      showCheckbox: false,
      fixedHeader: false,
      tableSize: 'small',
      createFlagTaskModal: false,
      formValidate: {
        name: '',
        instruct: '',
        selectedVmData: [],
        desc: '',
        vmName: '',
        vmIP: '',
        taskMode: 'normal'
      },
      ruleValidate: {
        name: [{ required: true, message: '', trigger: 'blur', validator: validateName }],
        instruct: [{ required: true, message: '请选择执行的指令', trigger: 'change' }],
        selectedVmData: [{ required: true, message: '请选择虚拟机' }],
        desc: []
      },
      vmCurrentPage: 1,
      vmItemPage: 10,
      vmTotal: 0,
      taskCurrentPage: 1,
      taskItemPage: 10,
      taskTotal: 0,
      judgePanelType: true, //判断是修改还是保存
      workingAreaTaskId: '', //存放修改的任务id

      //查看详情面板
      taskDeailModal: false,
      taskDeailColumns: [
        {
          type: 'expand',
          width: '30',
          render: (h, params) => {
            return h('div', {}, [
              h('Row', { props: { class: 'expand-row' } }, [
                h('Col', { props: { span: '8' }, style: { width: '50%' } }, [
                  h('span', { props: { class: 'expand-key' } }, 'host:  '),
                  h('span', { props: { class: 'expand-value' } }, params.row.host)
                ]),
                h('Col', { props: { span: '8' }, style: { width: '50%' } }, [
                  h('span', { props: { class: 'expand-key' } }, 'hostIP:  '),
                  h('span', { props: { class: 'expand-value' } }, params.row.hostIp)
                ])
              ]),
              h('Row', { props: { class: 'expand-row' } }, [
                h('Col', { props: { span: '8' }, style: { width: '100%' } }, [
                  h('span', { props: { class: 'expand-key' } }, 'instance_name:  '),
                  h('span', { props: { class: 'expand-value' } }, params.row.instance)
                ])
              ]),
              h('Row', { props: { class: 'expand-row' } }, [
                h('Col', { props: { span: '8' }, style: { width: '100%' } }, [
                  h('span', { props: { class: 'expand-key' } }, 'osId:  '),
                  h('span', { props: { class: 'expand-value' } }, params.row.osId)
                ])
              ])
            ]);
          }
        },
        {
          title: this.$t('name'),
          key: 'deviceName',
          align: 'center'
        },
        {
          title: this.$t('Status'),
          key: 'status',
          align: 'center',
          render: (h, params) => {
            return this.renderTaskStatus(h, params.row.status);
          }
        },
        // {
        //     title:this.$t('CreateTime'),
        //     key:'created',
        //     align:'center'
        // },
        // {
        //     title:this.$t('UpdateTime'),
        //     key:'updated',
        //     align:'center'
        // }
        // ,
        {
          title: this.$t('Message'),
          key: 'message',
          align: 'center'
        }
        // {
        //     title:this.$t('Operation'),
        //     key:'-',
        //     align:'center',
        //     render:(h,params)=>{
        //         let _this = this;
        //         return h("Button",{
        //             props:{
        //                 type:'primary'
        //             },
        //             on:{
        //                 click(){
        //                     _this.taskCollectDeailPanel = true
        //                     _this.taskCollectDeail(params.row.taskId)
        //                 }
        //             }
        //         },"查看结果")
        //     }
        // }
      ],
      taskDeailData: [],
      instructData: [
        {
          cmd: [],
          args: []
        }
      ],
      paramsData: [],
      _profileId: '',
      currentSceneId: '',
      propertiesData: [],
      tableHeight: '',
      currentTaskMode: '',
      disabledTepBol: false,
      processNodeId: '',
      tempTaskBol: false
    };
  },

  created() {
    this.currentProjectId = this.$route.query.prjid;
    this.currentSceneId = this.$route.query.id;
    // this.tableHeight = $(window).height() - 224 ;
    // this.currentProjectId = "430e0a1468ec43f78c31b5dce5c035e6"
    // localStorage.token = "d8854087b29641c79dce36ec0799476c"
    this.getTaskList({
      testId: this.currentSceneId,
      pageIndex: this.taskCurrentPage,
      pageSize: this.taskItemPage,
      taskType: this.taskTypeTable,
      taskMode: this.currentTaskMode
    });

    // console.log(this.currentProjectId)
    // alert('-')
  },
  methods: {
    getMsgFormSon(data) {
      this.propertiesData = data;
    },
    clickEvent: function() {
      // console.log('--')
      // console.log(this.headerData)
      // this.$emit("success",this.taskTypeTableTitle)
      // this.loadConfiguration(this.taskTypeTable)
      // this.loadConfiguration("outband_capture")
    },
    handleSelectAll(status) {
      this.$refs.selection.selectAll(status);
    },
    createFlagTask(nodeId = '') {
      this.tempTaskBol = false;
      // this.formValidate.taskMode = "normal";
      this.$refs['formValidate'].resetFields();
      if (typeof nodeId == 'string') {
        this.processNodeId = nodeId;
        if (nodeId == 'temp') {
          this.tempTaskBol = true;
          this.disabledTepBol = true;
          this.formValidate.taskMode = 'temp';
        }
      }
      this.judgePanelType = true;
      // this.$refs['formValidate'].resetFields();
      this.vmCurrentPage = 1;
      this.vmItemPage = 10;
      this.formValidate.configer = '';
      this.formValidate.vmName = '';
      this.formValidate.vmIP = '';
      this.configurationData = [];
      this.formValidate.taskMode = 'normal';
      this.propertiesData = [
        {
          key: '',
          value: ''
        }
      ];
      this.judgeVmStatus();
      // this.loadConfiguration("outband_capture")
      this.getVmList({
        pageIndex: this.vmCurrentPage,
        pageSize: this.vmItemPage,
        order: 'asc',
        sortBy: 'name',
        name: this.formValidate.vmName,
        ipAddress: this.formValidate.vmIP
      });
      this.createFlagTaskModal = true;
      // this.formValidate.name = "";

      this.formValidate.desc = '';
      // this.selectedVmDataTable = []
      this.selectedVmDataTable = [];
      this.formValidate.selectedVmData = [];
    },
    ok() {
      this.handleSubmit('formValidate');
    },
    cancel() {
      //  this.$Message.info('Clicked cancel')
    },
    handleSubmit(name) {
      let $this = this;
      this.properties = {};
      if (this.propertiesData.length != 0) {
        let attrData = $this.propertiesData;
        for (let index = 0; index < attrData.length; index++) {
          const element = attrData[index];
          if (element.key) {
            $this.properties[element.key] = element.value;
          }
        }
      }
      $this.$refs[name].validate((valid) => {
        if (valid) {
          // $this.$Message.success('Success!');
          $this.formValidate.name = $this.formValidate.name.replace(/\s*/g, '');
          if ($this.selectedVmDataTable.length != 0) {
            // alert($this.judgePanelType)
            for (let i = 0; i < $this.instructData[0].args.length; i++) {
              if (
                $this.instructData[0].args[i].mandatory &&
                !($this.instructData[0].args[i].value.trim())
              ) {
                $this.$Message.info('请填写参数');
                $this.createFlagTaskModalLoading = false;
                $this.$nextTick(() => {
                  $this.createFlagTaskModalLoading = true;
                });
                return;
              }
              // let _string = '"'+$.trim($this.instructData[0].args[i].key) +'",'+ '"'+$this.instructData[0].args[i].value + '"'
              // let _string = $.trim($this.instructData[0].args[i].key) +','+$this.instructData[0].args[i].value
              // console.log($this.instructData[0].cmd)
              // $this.instructData[0].cmd.splice(1,0,$.trim($this.instructData[0].args[i].key))
              // console.log($this.instructData[0].cmd)
              // if($this.instructData[0].args[i].value){
              //     console.log(parseInt($this.instructData[0].cmd.indexOf($.trim($this.instructData[0].args[i].key)))+1)
              //     $this.instructData[0].cmd.splice(parseInt($this.instructData[0].cmd.indexOf($.trim($this.instructData[0].args[i].key)))+1,0,$this.instructData[0].args[i].value)
              // }

              if ($this.instructData[0].args[i].value) {
                $this.instructData[0].cmd.splice(1, 0,$this.instructData[0].args[i].key.trim());
                // console.log(parseInt($this.instructData[0].cmd.indexOf($.trim($this.instructData[0].args[i].key)))+1)
                $this.instructData[0].cmd.splice(
                  parseInt(
                    $this.instructData[0].cmd.indexOf($this.instructData[0].args[i].key.trim())
                  ) + 1,
                  0,
                  $this.instructData[0].args[i].value
                );
              }
            }
            // $this.instructData[0].cmd.unshift($this.formValidate.instruct)
            if ($this.judgePanelType) {
              //判断是保存还是修改
              // return
              console.log($this.paramsData);
              $this.saveoutbandTask({
                name: $this.formValidate.name,
                // configId:$this.formValidate.configer,
                description: $this.formValidate.desc,
                deviceIdList: $this.selectedVmDataTable,
                deviceType: 'VM',
                taskType: $this.taskTypeTable,
                testId: $this.currentSceneId,
                metadata: {
                  allData: true,
                  cmd: $this.instructData[0].cmd,
                  osInfo: $this.paramsData[0].osInfo,
                  profile: $this.paramsData[0].profile,
                  instructId: $this.formValidate.instruct,
                  profileId: $this._profileId
                },
                properties: $this.properties,
                taskMode: $this.formValidate.taskMode
              });
            } else {
              console.log($this.paramsData);
              $this.amendTask({
                name: $this.formValidate.name,
                // configId:$this.formValidate.configer,
                description: $this.formValidate.desc,
                deviceIdList: $this.selectedVmDataTable,
                deviceType: 'VM',
                taskType: $this.taskTypeTable,
                testId: $this.currentSceneId,
                metadata: {
                  allData: true,
                  cmd: $this.instructData[0].cmd,
                  osInfo: $this.paramsData[0].osInfo,
                  profile: $this.paramsData[0].profile,
                  instructId: $this.formValidate.instruct,
                  profileId: $this._profileId
                },
                properties: $this.properties,
                taskMode: $this.formValidate.taskMode
              });
            }
          } else {
            $this.$Message.info('请选择虚拟机');
            $this.createFlagTaskModalLoading = false;
            $this.$nextTick(() => {
              $this.createFlagTaskModalLoading = true;
            });
          }
        } else {
        }
        $this.createFlagTaskModalLoading = false;
        this.$nextTick(() => {
          $this.createFlagTaskModalLoading = true;
        });
      });
    },
    handleReset(name) {
      this.$refs[name].resetFields();
    },
    addVmAfterTable(param) {
      let data = this.dataVmList;
      this.dataVmList.forEach((item, i) => {
        if (item.id == param.id) {
          item._checked = true;
          item._disabled = true;
        }
      });
    },
    handleAdd() {
      // if (this.selectedVmData.length) {
      //     this.selectedVmData.push(this.count[this.count.length - 1] + 1);
      // } else {
      //     this.selectedVmData.push(0);
      // }
    },
    handleClose2(event, name) {
      // console.log(event)
      // console.log(name);
      let $this = this;
      let data = this.formValidate.selectedVmData;
      let _data = this.selectedVmDataTable;
      $this.selectedDataConfiger = [];
      data.forEach((item, i) => {
        if (item) {
          if (item.id == name) {
            data.splice(i, 1);
            _data.splice(
              $this.selectedVmDataTable.findIndex((vmId) => vmId == name),
              1
            );
            // _data.remove(name);
            $this.judgeVmStatus();
          }
        }
      });
      if (data.length == 0) {
        $this.configurationData = [];
        $this.instructData = [
          {
            args: [],
            cmd: []
          }
        ];
      }

      // console.log(key);
      // const index = this.selectedVmData.indexOf(name);
      // this.count.splice(index, 1);
    },
    judgeVmStatus() {
      let data = this.dataVmList;
      let data_ = this.selectedVmDataTable;
      // console.log(data_)
      data.forEach((item, i) => {
        // console.log(item.id)
        if (data_.indexOf(item.id) != -1) {
          // alert('-')
          item._checked = true;
          item._disabled = true;
        } else {
          item._checked = false;
          item._disabled = false;
        }
      });
    },
    getVmList(getParamObj) {
      let $this = this;
      // axios({
      //     url:'topo/deployed/projects/'+this.currentProjectId+'/vms?'+this.BASE.getParamStr(getParamObj),
      //     // url: this.GLOBAL._projPath_deploy+'project/servers?'+this.BASE.getParamStr(getParamObj),
      // })
      getParamObj.projectId = this.currentProjectId;
      getAllVm(getParamObj).then((response) => {
        if (response.code == 1) {
          $this.dataVmList = [];
          let vmData = response.data.items;
          $this.vmTotal = Number(response.data.total);
          console.log(vmData, $this.selectedVmDataTable);
          vmData.forEach((item, i) => {
            //根据镜像ID查询profileId
            new Promise(function(resolve, reject) {
              axios({
                url: '/resource-manager/image/detail/' + item.imageId
              }).then((response) => {
                console.log('dataVmList1', response);
                if (response.code == 1) {
                  let attribute = response.data;
                  if (attribute.profileId) {
                    item.profile = attribute.profileName;
                    item.profileId = attribute.profileId;
                  } else {
                    item.profile = '';
                    item.profileId = '';
                  }
                }
                resolve();
              });
            }).then(function() {
                let disabled_ = false;
                let checked_ = false;
                if ($this.selectedVmDataTable.length != 0) {
                if ($this.selectedVmDataTable.indexOf(item.id) != -1) {
                  disabled_ = true;
                  checked_ = true;
                } else {
                  disabled_ = false;
                  checked_ = false;
                }
              } else {
                disabled_ = false;
                checked_ = false;
              }
              let IPS = [];
              if (item.addresses && item.addresses.length != 0) {
                for (let i = 0; i < item.addresses.length; i++) {
                  if (item.addresses[i].ips && item.addresses[i].ips.length != 0) {
                    for (let index = 0; index < item.addresses[i].ips.length; index++) {
                      const element = item.addresses[i].ips[index];
                      IPS.push(element.ipAddress);
                    }
                  }
                }
              }
              $this.dataVmList.push({
                name: item.name,
                id: item.id,
                IP: IPS,
                profile: (item.profile = item.profile ? item.profile : '-'),
                profileId: item.profileId,
                _disabled: disabled_,
                _checked: checked_,
                imageId: item.imageId
              });
              console.log('dataVmList', $this.dataVmList);
            });
          });
        } else {
          this.$Message.error(response.message);
        }
      });
    },
    getSelectedData(selection) {
      // console.log(selection)
      this.selectedDataConfiger = [];
      this.selectedDataConfiger = selection;
    },
    addSelectedData() {
      let that = this,
        bol = true;
      that.selectedDataConfiger.forEach((item, i) => {
        if (that.selectedVmDataTable.indexOf(item.id) != -1) {
          //虚拟机列表已有
        } else if (that.selectedVmDataTable.length >= 1 && item.profileId != that._profileId) {
          //profileId不同不能添加
        } else if (item.profileId) {
          //可以添加的
          bol = false;
          that.addVmAfterTable(item);
          that.selectedVmDataTable.push(item.id);
          that.formValidate.selectedVmData.push({
            name: item.name,
            id: item.id
          });
          that._profileId = item.profileId;
          // if(that._profileId){
          //     that.getInstructByVm()
          // }else{
          //     that.selectedVmDataTable = []
          //     that.formValidate.selectedVmData = []
          //     that.judgeVmStatus()
          //     that.$Message.error("查不到profileId")
          // }
        } else {
          //没有profileId
        }
      });
      if (bol) {
        if (that._profileId) {
          that.$Message.info('请选择要添加的内容');
        } else {
          that.$Message.info('查不到虚拟机的profile');
        }
      } else {
        that.getInstructByVm();
      }
    },
    switchineVmCurrentPage(numberPage) {
      this.vmCurrentPage = numberPage;
      this.getVmList({
        pageIndex: this.vmCurrentPage,
        pageSize: this.vmItemPage,
        order: 'asc',
        sortBy: 'name',
        name: this.formValidate.vmName,
        ipAddress: this.formValidate.vmIP
      });
    },
    switchVmItemPage(numberSize) {
      this.vmItemPage = numberSize;
      this.getVmList({
        pageIndex: this.vmCurrentPage,
        pageSize: this.vmItemPage,
        order: 'asc',
        sortBy: 'name',
        name: this.formValidate.vmName,
        ipAddress: this.formValidate.vmIP
      });
    },
    saveoutbandTask(saveDateJson) {
      console.log(saveDateJson);
      let $this = this;
      // axios({
      //     url:this.GLOBAL._projPath_process +"tasks",
      //     method:'POST',
      //     data:saveDateJson
      // })
      saveoutbandTask(saveDateJson).then((response) => {
        if (response.code == 1) {
          $this.createFlagTaskModal = false;
          this.taskCurrentPage = 1;
          this.taskItemPage = 10;
          $this.$Message.success('添加任务成功');
          $this.getTaskList({
            testId: $this.currentSceneId,
            pageIndex: $this.taskCurrentPage,
            pageSize: $this.taskItemPage,
            taskType: $this.taskTypeTable,
            taskMode: $this.currentTaskMode
          });
          // if(typeof($this.processNodeId)=="string"){
          //     if($this.tempTaskBol){
          //         axios({
          //             url:$this.GLOBAL._projPath_process +"tasks/"+response.data.id+'/execute?operation=start',
          //             method:'post'
          //         }).then((data)=>{
          //             let activeType;
          //             if(data.code==1){
          //                 $this.$Message.success("启动任务成功")
          //             }else{
          //                 $this.$Message.error(response.message)
          //             }
          //         })
          //     }else{
          //         axios({
          //             url:this.GLOBAL._projPath_process+'tasks/'+response.data.id+'?nodeId='+$this.processNodeId,
          //             method:'patch'
          //         }).then((data)=>{
          //             if (data.code==1) {
          //                 $this.processNodeId = "";
          //             } else {
          //                 $this.$Message.error(data.message)
          //             }
          //         })
          //     }
          // }else{
          //     $this.$parent.getStatisticsList();
          // }
        } else {
          this.$Message.error(response.message);
        }
      });
    },
    getTaskList(obj) {
      // alert('-')
      this.selectedData = [];
      let $this = this;
      // clearInterval($this.headerData.serintervalTimeFun)
      // axios({
      //     url:this.GLOBAL._projPath_process +"tasks?"+this.BASE.getParamStr(obj),
      // })
      getTaskList(obj).then((response) => {
        // response = {"code":1,"data":{"total":1,"items":[{"overview":{"initialized":1},"auto":false,"taskMode":"normal","creator":"fa59c23f197341b29cebb10e204ebccf","metadata":{"allData":true,"osInfo":"{ostype = \"Windows\";win_pdbase=0x18;win_pid=0x94;win_tasks=0x98;win_pname=0x164;}","profileId":"1","profile":"Win7_x64","cmd":["pslist","--output=json","--tz=PRC"],"instructId":"19"},"created":"2023-03-31 18:07:20","creatorName":"lili123","deviceData":[{"deviceType":"VM","taskType":"once_capture","rangeId":"R72128275322092504940582766018","rangeName":"cs0p20","id":"5207d3b7220f42d397efb0d79714b3b1","deviceId":"Va5c8fd26f8c42f1a2b14b031d1ea7e9","deviceName":"team001-test001-win","taskId":"17b527c8ea8448f8878f0d6bedd9f4a7","status":"initialized"}],"description":"","version":"master-1.0","taskType":"once_capture","useDisExecutor":false,"name":"测试","testId":"c0746016-b7b5-43f5-8f32-7e5fa29c1be6","id":"17b527c8ea8448f8878f0d6bedd9f4a7","internalKey":"17b527c8ea8448f8878f0d6bedd9f4a7","properties":{},"status":"initialized"}]}}
        if (response.code == 1) {
          $this.taskData = [];
          $this.taskTotal = response.data.total;
          let setintrvalBol = false;
          // let _s = 0,_e = 0,_i = 0,_r = 0,stintervalBol = false;
          if (response.data.items.length != 0) {
            $this.taskData = response.data.items;
            response.data.items.forEach((item, i) => {
              if (
                item.status == 'running' ||
                item.status == 'starting' ||
                item.status == 'closing'
              ) {
                setintrvalBol = true;
              }
            });
          }
          // if(setintrvalBol){
          //     $this.headerData.serintervalTimeFun  = setInterval( $this.setintervalTaskList, 2000);
          // }else{
          //     clearInterval($this.headerData.serintervalTimeFun)
          //     $this.setintervalTaskList();
          // }
          // $this.getTaskListDeailData()
          // $this.$emit("success",$this.taskTypeTableTitle+'-'+_s+'-'+_e+'-'+_i+'-'+_r+'-'+stintervalBol+'-'+$this.taskCurrentPage+'-'+$this.taskItemPage)
        } else if (response.code == -2) {
        } else {
          $this.$Message.error(response.message);
        }
      });
    },
    switchineTaskCurrentPage(numberPage) {
      this.taskCurrentPage = numberPage;
      this.getTaskList({
        testId: this.currentSceneId,
        pageIndex: this.taskCurrentPage,
        pageSize: this.taskItemPage,
        // "configType":"",
        taskType: this.taskTypeTable,
        taskMode: this.currentTaskMode
      });
    },
    switchTaskItemPage(numberSize) {
      this.taskItemPage = numberSize;
      this.getTaskList({
        testId: this.currentSceneId,
        pageIndex: this.taskCurrentPage,
        pageSize: this.taskItemPage,
        // "configType":"",
        taskType: this.taskTypeTable,
        taskMode: this.currentTaskMode
      });
    },
    deleteTask(taskId) {
      let $this = this;
      // axios({
      //     url:this.GLOBAL._projPath_process +"tasks/"+taskId,
      //     method:'delete'
      // })
      deleteTask(taskId).then((response) => {
        if (response.code == 1) {
          if (response.data[0].code == 1) {
            this.taskCurrentPage =
              this.taskData.length == 1 && this.taskCurrentPage > 1
                ? this.taskCurrentPage - 1
                : this.taskCurrentPage;
            $this.getTaskList({
              testId: $this.currentSceneId,
              pageIndex: $this.taskCurrentPage,
              pageSize: $this.taskItemPage,
              taskType: $this.taskTypeTable,
              taskMode: $this.currentTaskMode
            });
            $this.$Message.success('删除成功');
            // $this.$parent.getStatisticsList();
          } else {
            $this.$Message.error(response.data[0].message);
          }
        } else {
          $this.$Message.error(response.data[0].message);
        }
      });
    },
    updateTask(taskId) {
      this.judgePanelType = false;
      this.formValidate.vmName = '';
      this.formValidate.vmIP = '';
      let $this = this;
      // axios({
      //     url:this.GLOBAL._projPath_process +"tasks/"+taskId,
      // })
      taskDetail(taskId)
        .then((response) => {
          if (response.code == 1) {
            $this.workingAreaTaskId = response.data.id;
            $this.selectedVmDataTable = [];
            $this.formValidate.selectedVmData = [];
            $this.createFlagTaskModal = true;
            $this.propertiesData = [];
            $this.formValidate.name = response.data.name;
            $this.formValidate.desc = response.data.description;
            $this.formValidate.configer = response.data.configId;
            // $this.formValidate.instruct = reponse.data.metadata.cmd[0]
            $this._profileId = response.data.metadata.profileId;
            $this.getInstructList(
              $this._profileId,
              response.data.metadata.instructId,
              response.data.metadata.cmd
            );

            // $this.formValidate.instruct = reponse.data.metadata.instructId
            //  setTimeout(() => {
            //     $this.formValidate.instruct = reponse.data.metadata.instructId
            // }, 2000);
            // console.log($this.formValidate.instruct)
            if (response.data.deviceData.length != 0) {
              response.data.deviceData.forEach((item, i) => {
                $this.selectedVmDataTable.push(item.deviceId);
                $this.formValidate.instruct = item.deviceId;
                $this.formValidate.selectedVmData.push({
                  name: item.deviceName,
                  id: item.deviceId
                });
              });
            }
            $this.formValidate.taskMode = response.data.taskMode;
            if (JSON.stringify(response.data.properties) != '{}') {
              for (let i in response.data.properties) {
                let obj = {};
                obj['key'] = i;
                obj['value'] = response.data.properties[i];
                $this.propertiesData.push(obj);
              }
            }
          } else {
            $this.workingAreaTaskId = ''; //清空任务id
            $this.$Message.error(response.message);
          }
        })
        .then(() => {
          $this.getVmList({
            pageIndex: this.vmCurrentPage,
            pageSize: this.vmItemPage,
            order: 'asc',
            sortBy: 'name',
            name: this.formValidate.vmName,
            ipAddress: this.formValidate.vmIP
          });
          $this.judgeVmStatus();
        });
    },
    amendTask(amendTaskData) {
      let $this = this;
      // axios({
      //     url:this.GLOBAL._projPath_process+"tasks/"+this.workingAreaTaskId,
      //     method:'put',
      //     data:amendTaskData
      // })
      amendTask(this.workingAreaTaskId, amendTaskData).then((response) => {
        if (response.code == 1) {
          $this.$Message.success('修改成功');
          $this.createFlagTaskModal = false;
          $this.getTaskList({
            testId: $this.currentSceneId,
            pageIndex: $this.taskCurrentPage,
            pageSize: $this.taskItemPage,
            taskType: $this.taskTypeTable,
            taskMode: $this.currentTaskMode
          });
        } else {
          $this.$Message.error(response.message);
        }
      });
    },
    activeTask(taskId, active) {
      let $this = this;
      if (active == '开始') {
        active = 'start';
      } else if (active == '停止') {
        active = 'stop';
      }
      // axios({
      //     url:this.GLOBAL._projPath_process +"tasks/"+taskId+'/execute?operation='+active,
      //     method:'post',
      // })
      activeTask(taskId, active).then((response) => {
        let activeType;
        if (response.code == 1) {
          $this.$Message.success(active + '任务成功');
          $this.getTaskList({
            testId: $this.currentSceneId,
            pageIndex: $this.taskCurrentPage,
            pageSize: $this.taskItemPage,
            taskType: $this.taskTypeTable,
            taskMode: $this.currentTaskMode
          });
        } else {
          $this.$Message.error(response.message);
        }
      });
    },
    taskDeail(taskId) {
      let $this = this;
      // axios({
      //     url:this.GLOBAL._projPath_process +"tasks/"+taskId+'/histories',
      // })
      taskDetailHis(taskId).then((response) => {
        if (response.code == 1) {
          $this.taskDeailData = [];
          $this.taskDeailModal = true;
          // $this.taskDeailData= reponse.data;
          response.data.forEach((item, i) => {
            $this.taskDeailData.push({
              deviceName: item.deviceName,
              status: item.status,
              message: item.message,
              deviceId: item.deviceId,
              host: '',
              hostIp: '',
              instance: '',
              osId: '',
              _expanded: false,
              taskId: item.taskId,
              created: item.created ? item.created : '',
              updated: item.updated ? item.updated : ''
            });
          });
        } else {
          $this.$Message.error(response.message);
        }
      });
    },
    deleteManyTask(selection) {
      let $this = this;
      if (this.selectedData.length == 0) {
        this.$Message.error('请选择要删除的任务');
      } else {
        // axios({
        //     url:this.GLOBAL._projPath_process +"tasks/"+this.selectedData.map((item)=>item.id).join(','),
        //     method:'delete'
        // })
        deleteManyTask(this.selectedData.map((item) => item.id).join(',')).then((response) => {
          if (response.code == 1) {
            response.data.forEach((item, i) => {
              if (item.code == 1) {
                $this.taskCurrentPage =
                  $this.taskData.length == $this.selectedData.length && $this.taskCurrentPage > 1
                    ? $this.taskCurrentPage - 1
                    : $this.taskCurrentPage;
                $this.$Message.success('删除成功');
              } else {
                $this.$Message.error(item.message);
              }
            });
            $this.getTaskList({
              testId: $this.currentSceneId,
              pageIndex: $this.taskCurrentPage,
              pageSize: $this.taskItemPage,
              taskType: $this.taskTypeTable,
              taskMode: $this.currentTaskMode
            });
          } else {
            $this.$Message.error(response.message);
          }
        });
      }
    },
    getSelectedTableItem(selection) {
      this.selectedData = [];
      this.selectedData = selection;

      console.log(selection);
    },
    hostDeail(row) {
      console.log(row.deviceId);
      let $this = this;
      if (!row._expanded) {
        // axios({
        //     url:'topo/deployed/vms/'+row.deviceId,
        // })
        hostDetail(row.deviceId).then((response) => {
          if (response.code == 1) {
            $this.taskDeailData.forEach((item, i) => {
              if (row.deviceId == item.deviceId) {
                item._expanded = true;
                item.host = response.data.host;
                item.hostIp = response.data.hostIp;
                item.instance = response.data.instanceName;
                item.osId = response.data.cloudId;

                let IPS = [];
                let cidrs = [];
                if (response.data.addresses && response.data.addresses.length != 0) {
                  for (let i = 0; i < response.data.addresses.length; i++) {
                    if (
                      response.data.addresses[i].ips &&
                      response.data.addresses[i].ips.length != 0
                    ) {
                      for (let index = 0; index < response.data.addresses[i].ips.length; index++) {
                        const element = response.data.addresses[i].ips[index];
                        IPS.push(element.ipAddress);
                        cidrs.push(element.cidr);
                      }
                    }
                  }
                }

                item.IP = IPS;
                item.cidr = cidrs;
                return false;
              }
            });
          }
        });
      } else {
        row._expanded = !row._expanded;
      }
    },
    // setintervalTaskList(obj){
    //     let $this = this;
    //     $.ajax({
    //         type:"get",
    //         url:_projPath_process +"tasks?"+GlobalTool.getParamStr(obj),
    //         async:true,
    //         dataType:"json",
    //         headers:{"Authorization":localStorage.token},
    //         contentType:"application/json",
    //         success:function(reponse){
    //             if(reponse.code==1){
    //                 if(reponse.data.list.length!=0){
    //                     $.each(reponse.data.list,function(i,item){

    //                     })
    //                     $this.taskData = reponse.data.list;
    //                 }
    //             }else if(reponse.code==-2){

    //             }else{
    //                 $this.$Message.error(response.message)
    //             }
    //         },
    //         error:function(){
    //             $this.$Message.error(errorMessage)
    //         }
    //     });
    // },
    refreshTaskList() {
      this.getTaskList({
        testId: this.currentSceneId,
        pageIndex: this.taskCurrentPage,
        pageSize: this.taskItemPage,
        taskType: '',
        taskMode: this.currentTaskMode
      });
    },
    refreshVmList() {
      this.vmCurrentPage = 1;
      this.getVmList({
        pageIndex: this.vmCurrentPage,
        pageSize: this.vmItemPage,
        order: 'asc',
        sortBy: 'name',
        name: this.formValidate.vmName,
        ipAddress: this.formValidate.vmIP
      });
    },
    getTaskListDeailData() {
      let $this = this;
      // axios({
      //     url:this.GLOBAL._projPath_process +"overview/task/countByStatus?"+this.BASE.getParamStr({
      //         "testId":$this.currentSceneId,
      //         "taskType":$this.taskTypeTable,
      //         "node":"false"
      //     }),
      // })
      let params = {
        testId: $this.currentSceneId,
        taskType: $this.taskTypeTable,
        node: 'false'
      };
      getTaskListDetailData(params).then((response) => {
        if (response.code == 1) {
          let _s = 0,
            _e = 0,
            _i = 0,
            _r = 0,
            starting = 0,
            closing = 0,
            stintervalBol = false;
          _s = response.data.completed;
          _e = response.data.error;
          _i = response.data.initialized;
          _r =
            Number(response.data.running) +
            Number(response.data.starting) +
            Number(response.data.closing);
          starting = response.data.starting;
          closing = response.data.closing;
          if (_r != 0) {
            stintervalBol = true;
          }
          $this.$emit(
            'success',
            $this.taskTypeTableTitle +
              '-' +
              _s +
              '-' +
              _e +
              '-' +
              _i +
              '-' +
              _r +
              '-' +
              stintervalBol +
              '-' +
              $this.taskCurrentPage +
              '-' +
              $this.taskItemPage
          );
        } else if (response.code == -2) {
        } else {
          $this.$Message.error(response.message);
        }
      });
    },
    setintervalTaskList() {
      // alert('-')
      let $this = this;
      // axios({
      //     url:this.GLOBAL._projPath_process +"tasks?"+this.BASE.getParamStr({
      //         "testId":this.currentSceneId,
      //         "pageIndex":this.taskCurrentPage,
      //         "pageSize":this.taskItemPage,
      //         "taskType":this.taskTypeTable,
      //         // "node":'false'
      //     }),
      // })
      let params = {
        testId: this.currentSceneId,
        page: this.taskCurrentPage,
        rows: this.taskItemPage,
        taskType: this.taskTypeTable,
        node: 'false'
      };
      getTaskList(params).then((response) => {
        if (response.code == 1) {
          $this.taskData = [];
          if (response.data.items.length != 0) {
            let stintervalBol = false;
            $this.taskData = response.data.items;
            response.data.items.forEach((item, i) => {
              if (
                item.status == 'running' ||
                item.status == 'starting' ||
                item.status == 'closing'
              ) {
                stintervalBol = true;
              }
              $this.taskData[i].status = item.status;
            });
            if (!stintervalBol) {
              clearInterval($this.headerData.serintervalTimeFun);
            }
          }
          $this.getTaskListDeailData();
        } else if (response.code == -2) {
        } else {
          $this.$Message.error(response.message);
        }
      });
    },

    //根据虚拟机查询所具有的指令
    getInstructByVm() {
      let $this = this;
      $this.paramsData = [];
      $this.configurationData = [];
      axios({
        url: '/resource-manager/profile/list/detail?id=' + $this._profileId
      }).then((data) => {
        if (data.code == 1) {
          let attributes = data.data[0];
          // $this.configurationData =attributes.cmds
          for (let i = 0; i < attributes.cmds.length; i++) {
            $this.configurationData.push({
              datarows: attributes.cmds[i].dataRows,
              args: attributes.cmds[i].args,
              essentialarg: attributes.cmds[i].essentialArg,
              estime: attributes.cmds[i].esTime,
              id: String(attributes.cmds[i].id),
              name: attributes.cmds[i].name,
              note: attributes.cmds[i].note,
              slevel: attributes.cmds[i].slevel,
              type: attributes.cmds[i].type
            });
          }
          $this.paramsData.push({
            osInfo: attributes.content,
            profile: attributes.osName
            // cmd:[],
            // args:[],
          });
        } else {
          $this.$Message.error(data.message);
        }
      });
    },
    getInstructList(profileId, instructId, paramsCmd) {
      let $this = this;
      axios({
        url: '/resource-manager/profile/list/detail',
        data: {
          id: profileId
        }
      }).then((response) => {
        if (response.code == 1) {
          let attributes = response.data[0];
          $this.configurationData = [];
          // $this.configurationData =attributes.cmds
          for (let i = 0; i < attributes.cmds.length; i++) {
            $this.configurationData.push({
              datarows: attributes.cmds[i].dataRows,
              args: attributes.cmds[i].args,
              essentialarg: attributes.cmds[i].essentialArg,
              estime: attributes.cmds[i].esTime,
              id: String(attributes.cmds[i].id),
              name: attributes.cmds[i].name,
              note: attributes.cmds[i].note,
              slevel: attributes.cmds[i].slevel,
              type: attributes.cmds[i].type
            });
          }
          $this.paramsData = [];
          $this.paramsData.push({
            osInfo: attributes.content,
            profile: attributes.osName
            // cmd:[],
            // args:[],
          });
          $this.formValidate.instruct = instructId;
          let instruckKey = [];
          $this.instructData = [
            {
              args: [],
              cmd: []
            }
          ];
          let _name_instroll = null;
          $this.instructData[0].args = [];
          $this.instructData[0].cmd = [];
          for (let i = 0; i < $this.configurationData.length; i++) {
            if (instructId == $this.configurationData[i].id) {
              $this.instructData[0].cmd.push($this.configurationData[i].name);
              _name_instroll = $this.configurationData[i].name;
              for (let k = 0; k < $this.configurationData[i].args.length; k++) {
                let keyDesc = null;
                if (
                  $this.configurationData[i].args[k].key == '-p' ||
                  $this.configurationData[i].args[k].key == '-P'
                ) {
                  keyDesc = '进程';
                } else if (
                  $this.configurationData[i].args[k].key == '-o' ||
                  $this.configurationData[i].args[k].key == '-O'
                ) {
                  keyDesc = '地址';
                } else if (
                  $this.configurationData[i].args[k].key == '-a' ||
                  $this.configurationData[i].args[k].key == '-A'
                ) {
                  keyDesc = '内存地址';
                } else if (
                  $this.configurationData[i].args[k].key == '-K' ||
                  $this.configurationData[i].args[k].key == '-k'
                ) {
                  keyDesc = '路径';
                } else {
                  keyDesc = '';
                }
                $this.instructData[0].args.push({
                  key: $this.configurationData[i].args[k].key,
                  value: '',
                  mandatory: $this.configurationData[i].args[k].mandatory,
                  desc: keyDesc
                });
                instruckKey.push($this.configurationData[i].args[k].key);
              }
              // = $this.configurationData[i].args
              if ($this.configurationData[i].essentialarg) {
                for (
                  let j = 0;
                  j < $this.configurationData[i].essentialarg.split(',').length;
                  j++
                ) {
                  $this.instructData[0].cmd.push(
                    $this.configurationData[i].essentialarg.split(',')[j]
                  );
                }
              }
            }
          }
          //回显参数
          for (let i = 0; i < $this.instructData[0].args.length; i++) {
            if (
              instruckKey.indexOf(
                paramsCmd[paramsCmd.indexOf($this.instructData[0].args[i].key) + 1]
              ) == -1
            ) {
              //
              if (
                paramsCmd[paramsCmd.indexOf($this.instructData[0].args[i].key) + 1] !=
                  '--output=json' &&
                paramsCmd[paramsCmd.indexOf($this.instructData[0].args[i].key) + 1] != '--tz=PRC' &&
                paramsCmd[paramsCmd.indexOf($this.instructData[0].args[i].key) + 1] !=
                  _name_instroll
              ) {
                if ($this.instructData[0].args[i].key.indexOf('-') != -1) {
                  $this.instructData[0].args[i].value =
                    paramsCmd[paramsCmd.indexOf($this.instructData[0].args[i].key) + 1];
                }
              }
            }
          }
          console.log(_name_instroll);
          console.log($this.instructData[0].args);
          console.log($this.instructData[0].cmd);
        } else {
          $this.paramsData = [];
          this.$Message.error(response.message);
        }
      });
    },
    getInstructDeail(instructId) {
      let $this = this;
      $this.instructData = [
        {
          args: [],
          cmd: []
        }
      ];
      for (let i = 0; i < $this.configurationData.length; i++) {
        if (instructId == $this.configurationData[i].id) {
          $this.instructData[0].cmd.push($this.configurationData[i].name);
          for (let k = 0; k < $this.configurationData[i].args.length; k++) {
            let keyDesc = null;
            if (
              $this.configurationData[i].args[k].key == '-p' ||
              $this.configurationData[i].args[k].key == '-P'
            ) {
              keyDesc = '进程';
            } else if (
              $this.configurationData[i].args[k].key == '-o' ||
              $this.configurationData[i].args[k].key == '-O'
            ) {
              keyDesc = '地址';
            } else if (
              $this.configurationData[i].args[k].key == '-a' ||
              $this.configurationData[i].args[k].key == '-A'
            ) {
              keyDesc = '内存地址';
            } else if (
              $this.configurationData[i].args[k].key == '-K' ||
              $this.configurationData[i].args[k].key == '-k'
            ) {
              keyDesc = '路径';
            } else {
              keyDesc = '';
            }
            $this.instructData[0].args.push({
              key: $this.configurationData[i].args[k].key,
              value: '',
              mandatory: $this.configurationData[i].args[k].mandatory,
              desc: keyDesc
            });
          }
          // = $this.configurationData[i].args
          if ($this.configurationData[i].essentialarg) {
            for (let j = 0; j < $this.configurationData[i].essentialarg.split(',').length; j++) {
              $this.instructData[0].cmd.push($this.configurationData[i].essentialarg.split(',')[j]);
            }
          }
        }
      }
      console.log($this.instructData);
    },
    //查看单次任务采集结果
    taskCollectDeail(taskId) {
      // $('#reportTable').bootstrapTable("destroy")
      let oTrHeaderDate = [];
      let oTrTbodyDate = [];
      $('.title').css('display', 'none');
      $('.tableData').css('display', 'block');
      // $('.tableData').css('display','inline-block');
      $('#dataPanel')
        .find('pre')
        .remove();
      let _this = this;
      axios({
        url: '/process/tasks/' + taskId + '/histories'
      }).then((response) => {
        if (response.code == 1) {
          let datas = response.data[0];
          if (datas.status == 'completed') {
            axios({
              url: '/data/kvm/oob/once?id=' + datas.id
            }).then((reponse) => {
              $('#reportTable').bootstrapTable('destroy');
              if (reponse.code == 1) {
                oTrHeaderDate = [];
                oTrTbodyDate = [];
                let data = _this.BASE.isJSON(reponse.data.retStr);
                console.log(data);
                //判断是否为json格式bootstrapTable("refresh")
                if (data) {
                  data = JSON.parse(reponse.data.retStr);
                  let headerDate = data.columns;
                  headerDate.unshift('序号');
                  let tbodyDate = data.rows;
                  let oTrHeaderDate = [];
                  headerDate.forEach((item, i) => {
                    let obj = {};
                    // obj['index'] = i;
                    obj['field'] = item;
                    obj['title'] = item;
                    obj['align'] = 'center';
                    obj['valign'] = 'middle';
                    obj['sortable'] = 'true';
                    oTrHeaderDate.push(obj);
                  });
                  // $('#oneCaptureHeader').append(oTrHader);
                  let oTrTbody = '';
                  let oTrTbodyDate = [];
                  tbodyDate.forEach(function(i, item) {
                    let o = {};
                    item.unshift(i + 1);
                    item.forEach(function(m, n) {
                      headerDate.forEach(function(k, l) {
                        if (m == k) {
                          o[l] = n;
                        }
                      });
                    });
                    oTrTbodyDate.push(o);
                  });
                  $('#reportTable').bootstrapTable({
                    method: 'get',
                    cache: false,
                    height: 600,
                    striped: true,
                    pagination: true,
                    pageSize: 20,
                    pageNumber: 1,
                    pageList: [10, 20, 50, 100, 200, 500],
                    sidePagination: 'client',
                    search: false,
                    showColumns: true,
                    showRefresh: false,
                    showExport: false,
                    clickToSelect: true,
                    exportTypes: ['csv', 'txt', 'xml'],
                    search: false,
                    clickToSelect: true,
                    // showToggle: true,
                    columns: oTrHeaderDate,
                    data: oTrTbodyDate
                  });
                  $('#reportTable').bootstrapTable({ columns: oTrHeaderDate, data: oTrTbodyDate });
                } else {
                  //非json字符串
                  $('#dataPanel')
                    .find('pre')
                    .remove();
                  let noJson = reponse.data.retStr;
                  noJson = noJson.split('---------------------------------------------------');
                  noJson.forEach(function(i, item) {
                    let oP = `<pre style="border:1px solid #ddd;border-radius:5px;margin-top:10px;padding:10px">${item}</pre>`;
                    $('#dataPanel').append(oP);
                  });
                }
              } else if (reponse.code == 0) {
                $('.title').css('display', 'block');
                $('.title').text('未查询到采集结果');
                $('.tableData').css('display', 'none');
              } else {
                $('.title').css('display', 'block');
                $('.title').text('未查询到采集结果');
                $('.tableData').css('display', 'none');
              }
            });
          } else if (datas.status == 'error' || datas.status == 'failed') {
            $('.title').css('display', 'block');
            $('.title').text('启动失败');
            $('.tableData').css('display', 'none');
          } else if (datas.status == 'running') {
            $('.title').css('display', 'block');
            $('.title').text('正在采集中');
            $('.tableData').css('display', 'none');
          } else {
            $('.title').text('');
            $('.tableData').css('display', 'none');
          }
        } else {
        }
      });
    }
  },
  watch: {
    listenParam() {
      // console.log(this.buttonsName)
    }
  }
};
</script>
<style scoped>
  .headerBtn {
    text-align: left;
    margin: 10px;
  }
  .pageStyle {
    text-align: right;
  }
  .ivu-table-wrapper {
    overflow: visible;
  }
  .pageStyleVm {
    text-align: center;
    margin-top: 10px;
  }
  table .ivu-poptip-confirm .ivu-poptip-body .ivu-icon {
    left: 11px;
  }
  .position_i {
    position: relative;
    top: -1px;
    margin-right: 5px;
  }
  /* td{
      border-right: 0 !important
  } */
  .ivu-table-tip {
    overflow: hidden !important;
  }
  .starlet {
    color: red;
    position: absolute;
    left: -60px;
    font-size: 18px;
    line-height: 38px;
    font-weight: 800;
  }
  .zIndexStyleBtn {
    position: relative;
    z-index: 55;
  }
  .flex-wrap {
    display: flex;
    flex-wrap: wrap;
  }
  </style>